package pl.druminski.robinhood.view;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.TextAttribute;
import java.util.Hashtable;
import javax.swing.JLabel;

public class HyperLinkView extends JLabel
{

    private Font srcFont;

    public HyperLinkView()
    {
        this("");
    }

    public HyperLinkView(String text)
    {
        super(text);
        setForeground(Color.BLUE);
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        srcFont = this.getFont();
        addMouseListener(new MouseAdapter()
        {

            @Override
            public void mouseEntered(MouseEvent e)
            {
                Font font = srcFont;
                Hashtable<TextAttribute, Object> attributes = new Hashtable<TextAttribute, Object>();
                attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
                HyperLinkView.this.setFont(font.deriveFont(attributes));
            }



            @Override
            public void mouseExited(MouseEvent e)
            {
                HyperLinkView.this.setFont(srcFont);
            }
        });
    }
}
